package com.hzz.web.app.user;


import com.hzz.api.user.IUserService;
import com.hzz.dto.user.UserDto;
import com.hzz.framework.PageUtil;
import com.hzz.framework.Response;
import com.hzz.framework.annotation.auth.RequiresPermissions;
import com.hzz.framework.config.EncryptConfig;
import com.hzz.framework.util.CommonConstant;
import com.hzz.framework.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "组织体系-人员信息")
@RestController("apiRiverStaffController")
@Slf4j
public class RiverStaffController extends BaseController {
    @Autowired
    EncryptConfig encryptConfig;
    @Autowired
    IUserService userService;
    static final String acPrefix = "/api/staff/riverStaff/";

    //@RequiresPermissions("riverStaff:menu")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "page/{pageNum}")
    @ApiOperation(value = "信息分页(未删除)")
    public Response page(@RequestBody UserDto dto, @PathVariable("pageNum") Integer pageNum) {
        log.info("page.........");
        Response result = new Response();
        try {
            dto.setPageSize(CommonConstant.PAGEROW_DEFAULT_COUNT);
            dto.setPageNum(pageNum);
            dto.setDelFlag(0);
            dto.setType(CommonConstant.TYPE_普通人员);
            result.data = PageUtil.copy(userService.findDataIsPage(dto));
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }

    //@RequiresPermissions("riverStaff:menu")
    @RequestMapping(method = {RequestMethod.POST, RequestMethod.GET}, value = acPrefix + "list")
    @ApiOperation(value = "信息列表(未删除)", notes =
            "areaId:行政区划id,多个逗号[,]分割\n" +
                    "orgId:机构id\n" +
                    "type:1河长,2巡查员,3联系部门,18总河长,19副总河长")
    //{areaId: '', orgId: '', type: '', job: ''}
    public Response list(@RequestBody UserDto dto) {
        log.info("list.........");
        Response result = new Response();
        try {
            if (dto.getType() == null) {
                return Response.error("type必填!");
            }
            switch (dto.getType()) {
                case 1: {
                    dto.setType(CommonConstant.TYPE_河长);
                    break;
                }
                case 2: {
                    dto.setType(null);
                    dto.setJob("巡查员");
                    break;
                }
                case 18: {
                    dto.setType(CommonConstant.TYPE_总河长);
                    dto.setJob("总河长");
                    break;
                }
                case 19: {
                    dto.setType(CommonConstant.TYPE_副总河长);
                    dto.setJob("副总河长");
                    break;
                }
                case 3: {
                    dto.setType(null);
                    if (dto.getOrgId() == null) {
                        return Response.error("orgId必填!");
                    }
                    break;
                }
            }
            dto.setDelFlag(0);
            result.data = userService.findRiverStaffIsList(dto);
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }


    //@RequiresPermissions("riverStaff:info")
    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = acPrefix + "info/{id}")
    @ApiOperation(value = "信息详情")
    public Response info(@PathVariable("id") Long id) {
        log.info("info.........");
        Response result = new Response();
        try {
            UserDto dto = new UserDto();
            dto.setId(id);
            dto.setDelFlag(0);
            dto.setType(CommonConstant.TYPE_普通人员);
            result.data = userService.findDataById(dto);
        } catch (Exception e) {
            result = Response.error(e.getMessage());
        }
        return result;
    }
}
